#pragma once

// HX includes
#include "HXAlive.h"

using namespace std;


enum HXTTSEngineID {
  HXSAPI,
  HXOpenMary
};


class HXTTSEngine
{
public:
	HXTTSEngine(void);
	//HXTTSEngine(int fps, double visemeModulator, double rate); 
	~HXTTSEngine(void);

	void SetFPS(int fps) { m_fps = fps; };
	int GetFPS() { return m_fps; };

	void SetVisemeModulator(double visemeModulator) { m_visemeModulator = visemeModulator; };
	double GetVisemeModulator() { return m_visemeModulator; };

	void SetAVSyncAdjust(double avSyncAdjust) { m_avSyncAdjust = avSyncAdjust; };
	double GetAVSyncAdjust() { return m_avSyncAdjust; };

	void SetRate(double rate) { m_rate = rate; }
	double GetRate() { return m_rate; }

	void SetRampFunc(HXBlendMode mode) { m_rampFunc = mode; }
	HXBlendMode GetRampFunc() { return m_rampFunc; }

	void SetOverlap(double overlap) { m_overlap = overlap; }

	void SetVisemeMap(map<wstring,vector<vector<HXVisemeBlendShape>>>& visemeMap) { m_visemeMap = visemeMap; };

	// functions to be implemented by subclasses
	virtual HRESULT GenerateSpeech(const wstring& text,  string& audio, vector<vector<HXViseme>>& frames) = 0;
	virtual void    GetVoices(vector<string>& voices) = 0;
	virtual void    SetVoice(string& voice) = 0;
	virtual void    SetEffect(string& effect, string& value) = 0;
	void			SetEnginekHz(int kHz) { m_enginekHz = kHz; };
	
protected:
	
	// common functions 
	void ToHXViseme(string& phone, double endpoint, double previous, vector<vector<HXViseme>>& visemeSequence);
	int AddToVisemeSequence(const HXViseme& vin, vector<vector<HXViseme>>& output);
	int AddToFrame(const HXViseme& vin, vector<HXViseme>& output);
	double CalcRamp(double cframe, double sframe, double eframe, HXBlendMode rampFunc);
		
	int m_fps;
	double m_visemeModulator;
	double m_rate;
	double m_avSyncAdjust;
	double m_overlap;
	int m_enginekHz;
	HXBlendMode m_rampFunc;

	map<wstring,vector<vector<HXVisemeBlendShape>>> m_visemeMap;
};
